------------------- Khach Hang-----------------
--------Update------------
if exists (select name from sysobjects where name like 'Proc_KhachHang_Update')
	drop procedure Proc_KhachHang_Update
go

create PROC Proc_KhachHang_Update (@maKH int,@ten nvarchar(50),@cmnd int,@passPost nchar(10),
		@ngaySinh datetime, @diaChi nvarchar(50),@maSoThue nchar(50), @giayPhep nchar (10),@nguoiDaiDien nvarchar (50),  @SoDT char(10) )
as
set tran isolation level read committed
begin tran
		Update KhachHang 
		set Ten= @ten,CMND = @cmnd, PassPost = @passPost, NgaySinh = @ngaySinh, DiaChi= @diaChi, 
			MaSoThue = @maSoThue, GiayPhepKinhDoanh = @giayPhep, NguoiDaiDien= @nguoiDaiDien,  SoDT=@SoDT
		where MaKH =@maKH 
rollback
go

Exec Proc_KhachHang_Update 1,'Khanh',12345,'123H','05/02/2012','12 NND','354','MN123','thien','1234567890'
go

select * 
from KhachHang 
go

--------View------------

if exists (select name from sysobjects where name like 'sp_DSLoaiKH')
	drop procedure sp_DSLoaiKH
go
create proc sp_DSLoaiKH
as
begin
	select * from LoaiKH where DelFlg=0
end
go

if exists (select name from sysobjects where name like 'sp_DanhSachKhachHang')
	drop procedure sp_DanhSachKhachHang
go

create proc sp_DanhSachKhachHang
as
set tran isolation level read committed
begin tran
	select kh.MaKH,kh.Ten,kh.DiaChi,kh.MaLoaiKH,kh.MaTruSo,kh.SoDT,loai.TenLoai as LoaiKH,ts.Ten as ChiNhanh 
	from KhachHang kh,LoaiKH loai,TruSo ts 
	where kh.MaLoaiKH=loai.MaLoai and kh.MaTruSo=ts.MaTruSo
commit tran
go
-------------------------